import Https from "../../../utils/api"
const http = new Https
Page({
  data: {
    newsList: [],
    page: 1,
    last_page: 0,
  },
  onLoad: function (options) {

  },
  //第一次加载信息
  getList() {
    let that = this;
    http.request('news/list', {
      page: 1,//传递页数第一页
    }).then(res => {
      console.log(res)
      //保存数据
      this.setData({
        newsList: res.data[0],
        last_page: res.data['last_page'],
      })
    })
  },
  todetail: function (e) {
    var that = this;
    const data = that.data.newsList[e.target.dataset.options];
    const target = JSON.stringify(data);
    
    wx.navigateTo({
      url: './detail/detail?info=' + target
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getList()
  },
  //触底加载影城信息
  chudi_cineplex() {
    let page = this.data.page + 1;
    let last_page = this.data.last_page;
    if (page > last_page) {
      wx.showToast({
        title: '到底了',
      })
      return
    }
    http.request('news/list', {
      page: page,//传递页数第一页
    }).then(res => {
      //保存数据
      let arr = this.data.newsList
      let newsList = [...arr, ...res.data[0]]
      this.setData({
        newsList,
        page: page
      })
    })
  },
  /**
        * 页面上拉触底事件的处理函数
        */
  onReachBottom: function () {
    this.chudi_cineplex()
  },
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function (e) {
    wx.showLoading({
      title: '加载成功',
      mask: true,
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 500)
    this.getList()

  },
})
